home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Overview / Sample / Sample.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  9.5 KB  |  234 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple Sample Application
  6. #
  7. #    Sample
  8. #
  9. #    Sample.h    -    Rez and C Include Source
  10. #
  11. #    Copyright © 1989 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #                1.00                08/88
  16. #                1.01                11/88
  17. #                1.02                04/89
  18. #                1.03                06/89
  19. #                1.04                06/92
  20. #
  21. #    Components:
  22. #                Sample.p            June 1, 1989
  23. #                Sample.c            June 1, 1989
  24. #                SampleInit.c        June 2, 1992
  25. #                Sample.a            June 1, 1989
  26. #                Sample.inc1.a        June 1, 1989
  27. #                SampleMisc.a        June 1, 1989
  28. #                Sample.r            June 1, 1989
  29. #                Sample.h            June 1, 1989
  30. #                PSample.make        June 1, 1989
  31. #                CSample.make        June 1, 1989
  32. #                ASample.make        June 1, 1989
  33. #                CSample.π            June 2, 1992
  34. #                CSample.π.rsrc        June 2, 1992
  35. #
  36. #    Sample is an example application that demonstrates how to
  37. #    initialize the commonly used toolbox managers, operate 
  38. #    successfully under MultiFinder, handle desk accessories, 
  39. #    and create, grow, and zoom windows.
  40. #
  41. #    It does not by any means demonstrate all the techniques 
  42. #    you need for a large application. In particular, Sample 
  43. #    does not cover exception handling, multiple windows/documents, 
  44. #    sophisticated memory management, printing, or undo. All of 
  45. #    these are vital parts of a normal full-sized application.
  46. #
  47. #    This application is an example of the form of a Macintosh 
  48. #    application; it is NOT a template. It is NOT intended to be 
  49. #    used as a foundation for the next world-class, best-selling, 
  50. #    600K application. A stick figure drawing of the human body may 
  51. #    be a good example of the form for a painting, but that does not 
  52. #    mean it should be used as the basis for the next Mona Lisa.
  53. #
  54. #    We recommend that you review this program or TESample before 
  55. #    beginning a new application.
  56. ------------------------------------------------------------------------------*/
  57.  
  58. /* In MPW 3.0 and THINK C we can use actual prototypes for parameter type checking. */
  59. /* Function prototypes for all functions in this program. */
  60.  
  61. #ifndef rez
  62. void EventLoop( void );
  63. void DoEvent( EventRecord *event );
  64. void AdjustCursor( Point mouse, RgnHandle region );
  65. void GetGlobalMouse( Point *mouse );
  66. void DoUpdate( WindowPtr window );
  67. void DoActivate( WindowPtr window, Boolean becomingActive );
  68. void DoContentClick( WindowPtr window );
  69. void DrawWindow( WindowPtr window );
  70. void AdjustMenus( void );
  71. void DoMenuCommand( long menuResult );
  72. void SetLight( WindowPtr window, Boolean newStopped );
  73. Boolean DoCloseWindow( WindowPtr window );
  74. void Terminate( void );
  75. void ForceEnvirons( void );
  76. Boolean IsAppWindow( WindowPtr window );
  77. Boolean IsDAWindow( WindowPtr window );
  78. void AlertUser( void );
  79. void Initialize( void );
  80. Boolean GoGetRect( short rectID, Rect *theRect );
  81. Boolean TrapAvailable( short tNumber, TrapType tType );
  82. #endif
  83.  
  84. /*    These #defines correspond to values defined in the Pascal source code.
  85.     Sample.c and Sample.r include this file. */
  86.  
  87. /*    Determining an application's minimum size to request from MultiFinder depends
  88.     on many things, each of which can be unique to an application's function,
  89.     the anticipated environment, the developer's attitude of what constitutes
  90.     reasonable functionality and performance, etc. Here is a list of some things to
  91.     consider when determining the minimum size (and preferred size) for your
  92.     application. The list is pretty much in order of importance, but by no means
  93.     complete.
  94.     
  95.     1.    What is the minimum size needed to give almost 100 percent assurance
  96.         that the application won't crash because it ran out of memory? This
  97.         includes not only things that you do have direct control over such as
  98.         checking for NIL handles and pointers, but also things that some
  99.         feel are not so much under their control such as QuickDraw and the
  100.         Segment Loader.
  101.         
  102.     2.    What kind of performance can a user expect from the application when
  103.         it is running in the minimum memory configuration? Performance includes
  104.         not only speed in handling data, but also things like how many documents
  105.         can be opened, etc.
  106.         
  107.     3.    What are the typical sizes of scraps [is a boy dog] that a user might
  108.         wish to work with when lauching or switching to your application? If
  109.         the amount of memory is too small, the scrap may get lost [will have
  110.         to be shot]. This can be quite frustrating to the user.
  111.         
  112.     4.    The previous items have concentrated on topics that tend to cause an
  113.         increase in the minimum size to request from MultiFinder. On the flip
  114.         side, however, should be the consideration of what environments the
  115.         application may be running in. There may be a high probability that
  116.         many users with relatively small memory configurations will want to
  117.         avail themselves of your application. Or, many users might want to use it
  118.         while several other, possibly related/complementary applications are
  119.         running. If that is the case, it would be helpful to have a fairly
  120.         small minimum size.
  121.     
  122.     So, what did we decide on Sample? First, Sample has little risk of
  123.     running out of memory once it starts. Second, performance isn't much
  124.     of an issue since it doesn't do much and multiple windows are not
  125.     allowed. Third, there are no edit operations in Sample itself, so we
  126.     just want to provide enough space for a reasonable scrap to survive
  127.     between desk accessory launches. Lastly, Sample should intrude as little
  128.     as possible, so the effort should be towards making it as small as possible.
  129.     We looked at some heap dumps while the application was running under
  130.     various partition sizes. With a size of 23K, there was approximately
  131.     8-9K free, which is a good 'slop' factor in an application like this
  132.     which doesn't do much, but where we'd still like the scrap to survive
  133.     most of the time. */
  134.  
  135. #define kMinSize    23                /* application's minimum size (in K) */
  136.  
  137. /*    We made the preferred size bigger than the minimum size by 12K, so that
  138.     there would be even more room for the scrap, FKEYs, etc. */
  139.  
  140. #define kPrefSize    35                /* application's preferred size (in K) */
  141.  
  142. #define    rMenuBar    128                /* application's menu bar */
  143. #define    rAboutAlert    128                /* about alert */
  144. #define    rUserAlert    129                /* error user alert */
  145. #define    rWindow        128                /* application's window */
  146. #define rStopRect    128                /* rectangle for Stop light */
  147. #define rGoRect        129                /* rectangle for Go light */
  148.  
  149. /* kSysEnvironsVersion is passed to SysEnvirons to tell it which version of the
  150.    SysEnvRec we understand. */
  151.  
  152. #define    kSysEnvironsVersion        1
  153.  
  154. /* kOSEvent is the event number of the suspend/resume and mouse-moved events sent
  155.    by MultiFinder. Once we determine that an event is an osEvent, we look at the
  156.    high byte of the message sent to determine which kind it is. To differentiate
  157.    suspend and resume events we check the resumeMask bit. */
  158.  
  159. #define    kOSEvent                app4Evt    /* event used by MultiFinder */
  160. #define    kSuspendResumeMessage    1        /* high byte of suspend/resume event message */
  161. #define    kResumeMask                1        /* bit of message field for resume vs. suspend */
  162. #define    kMouseMovedMessage        0xFA    /* high byte of mouse-moved event message */
  163. #define    kNoEvents                0        /* no events mask */
  164.  
  165. /* The following constants are used to identify menus and their items. The menu IDs
  166.    have an "m" prefix and the item numbers within each menu have an "i" prefix. */
  167.  
  168. #define    mApple                    128        /* Apple menu */
  169. #define    iAbout                    1
  170.  
  171. #define    mFile                    129        /* File menu */
  172. #define    iNew                    1
  173. #define    iClose                    4
  174. #define    iQuit                    12
  175.  
  176. #define    mEdit                    130        /* Edit menu */
  177. #define    iUndo                    1
  178. #define    iCut                    3
  179. #define    iCopy                    4
  180. #define    iPaste                    5
  181. #define    iClear                    6
  182.  
  183. #define    mLight                    131        /* Light menu */
  184. #define    iStop                    1
  185. #define    iGo                        2
  186.  
  187. /*    1.01 - kTopLeft - This is for positioning the Disk Initialization dialogs. */
  188.  
  189. #define kDITop                    0x0050
  190. #define kDILeft                    0x0070
  191.  
  192. /*    1.01 - kMinHeap - This is the minimum result from the following
  193.     equation:
  194.         
  195.         ORD(GetApplLimit) - ORD(ApplicZone)
  196.         
  197.     for the application to run. It will insure that enough memory will
  198.     be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  199.     application, and still give the application some 'breathing room'.
  200.     To derive this number, we ran under a MultiFinder partition that was
  201.     our requested minimum size, as given in the 'SIZE' resource. */
  202.      
  203. #define kMinHeap                21 * 1024
  204.     
  205. /*    1.01 - kMinSpace - This is the minimum result from PurgeSpace, when called
  206.     at initialization time, for the application to run. This number acts
  207.     as a double-check to insure that there really is enough memory for the
  208.     application to run, including what has been taken up already by
  209.     pre-loaded resources, the scrap, code, and other sundry memory blocks. */
  210.      
  211. #define kMinSpace                8 * 1024
  212.  
  213. /* kExtremeNeg and kExtremePos are used to set up wide open rectangles and regions. */
  214.  
  215. #define kExtremeNeg                -32768
  216. #define kExtremePos                32767 - 1 /* required to address an old region bug */
  217.  
  218. /* these #defines are used to set enable/disable flags of a menu */
  219.  
  220. #define AllItems    0b1111111111111111111111111111111    /* 31 flags */
  221. #define NoItems        0b0000000000000000000000000000000
  222. #define MenuItem1    0b0000000000000000000000000000001
  223. #define MenuItem2    0b0000000000000000000000000000010
  224. #define MenuItem3    0b0000000000000000000000000000100
  225. #define MenuItem4    0b0000000000000000000000000001000
  226. #define MenuItem5    0b0000000000000000000000000010000
  227. #define MenuItem6    0b0000000000000000000000000100000
  228. #define MenuItem7    0b0000000000000000000000001000000
  229. #define MenuItem8    0b0000000000000000000000010000000
  230. #define MenuItem9    0b0000000000000000000000100000000
  231. #define MenuItem10    0b0000000000000000000001000000000
  232. #define MenuItem11    0b0000000000000000000010000000000
  233. #define MenuItem12    0b0000000000000000000100000000000
  234.